
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "user_uart_serial.h"
#include "user_lte_drive.h"
#include "user_fushi_drive.h"

#define LTE_TIME_OUT (600)
#define USER_RECVBUFF_LEN (64)
static uint8_t lte_recv_flag=0;
static uint8_t lte_recv_flag_tmp=0;
static uint8_t lte_recv_flag_tmp_times=0;
static uint8_t lte_recv_flag_tmp_times_times=0;

//static uint8_t lte_action_flag=0;
static uint8_t lte_action_sendtime=0;
static uint8_t lte_action_times_flag=0;
//
//static uint8_t lte_init_flag=0;

const uint8_t at_cmd[]="AT\r\n";
const uint8_t at_sim_cmd[]="AT+CPIN?\r\n";
const uint8_t at_cs_cmd[]="AT+CREG?\r\n";
const uint8_t at_ps_cmd[]="AT+CGREG?\r\n";
const uint8_t at_scence_cmd[]="AT+QICSGP=1,1,\"CMNET\",\"\",\"\",1\r\n";//配置 PDP 上下文的
const uint8_t at_action_cmd[]="AT+QIACT=1\r\n";                         //通过 AT+QIACT
const uint8_t at_action_check_cmd[]="AT+QIACT?\r\n";
/****************************************************************************************/
const uint8_t at_tcp_connect_cmd[]="AT+QIOPEN=1,0,\"TCP\",\"223.94.38.40\",8009,0,2\r\n";
const uint8_t at_tcp_close_cmd[]="AT+QICLOSE=0\r\n";
const uint8_t at_tcp_out_cmd[]="+++";


const uint8_t at_http_head_cmd[]="AT+QHTTPCFG=\"requestheader\",1\r\n";

const uint8_t at_http_url_cmd[]="AT+QHTTPURL=56,80\r\n";
const uint8_t at_http_url_data[]="http://43.142.99.138:5000/corrosion/multiplicityshowdata\r\n";
const uint8_t at_http_post_cmd[]="AT+QHTTPPOST=75,80,80\r\n";
//发送 HTTP POST 请求，通过 UART 获取 POST 请求体。POST请求体的最大输入时间和响应时间皆为 80 秒。
const uint8_t at_http_post_data[]="123\r\n";


static USER_UART_SERIAL_T user_lte_serial_handle;

static uint8_t user_lte_recvbuff[USER_RECVBUFF_LEN];
static uint8_t user_lte_recvbuff_tmp[USER_RECVBUFF_LEN];
static uint8_t user_lte_recvbuff_tmp2[USER_RECVBUFF_LEN];

void user_lte_drive_init(void)
{
	memset(user_lte_recvbuff,0, sizeof(user_lte_recvbuff));
	
	user_lte_serial_handle.user_recvstart=0;
	user_lte_serial_handle.user_recvend=0;
	user_lte_serial_handle.user_recvbuff=user_lte_recvbuff;
	user_lte_serial_handle.user_recvbuff_len=sizeof(user_lte_recvbuff);
	user_uart_serial_init(&user_lte_serial_handle);
}
void user_lte_action(void)
{
	//printf("lte_action_times_flag %d %d\r\n",lte_action_sendtime,lte_action_times_flag);
	if(lte_action_sendtime>5)
	{
		if(0==lte_action_times_flag)
		{
			HAL_GPIO_WritePin(LTE_POW_ON_GPIO_Port, LTE_POW_ON_Pin, GPIO_PIN_SET);
		}
		
		if(lte_action_times_flag==3)
		{
			HAL_GPIO_WritePin(LTE_POW_ON_GPIO_Port, LTE_POW_ON_Pin, GPIO_PIN_RESET);
			lte_action_sendtime=0;
			lte_action_times_flag=0;
		}
		lte_action_times_flag++;
	}
	else
	{
		//printf("lte_action_times_flag 0\r\n");
		lte_action_times_flag=0;
	}

}

void user_lte_drive_send(UART_HandleTypeDef *huart,USER_CENTRAL_CONTROL_STATUS_T *status)
{
	uint16_t crc_tmp;
	printf("user_lte_drive_send is %d\r\n",lte_recv_flag);
	/*
	if(status->central_control_net_flag==0)
	{
		return;
	}
	*/
	switch(lte_recv_flag)
	{
		case 0x00:
		{
			HAL_UART_Transmit(huart , (uint8_t *)at_cmd, strlen((const char *)at_cmd), 2000);
			lte_action_sendtime++;
			lte_recv_flag_tmp=0;
		}
		break;
		case 0x01:
		{
			HAL_UART_Transmit(huart , (uint8_t *)at_sim_cmd, strlen((const char *)at_sim_cmd), 2000);
		}
		break;
		case 0x02:
		{
			
			HAL_UART_Transmit(huart , (uint8_t *)at_cs_cmd, strlen((const char *)at_cs_cmd), 2000);
			HAL_GPIO_WritePin(GPIOB, LTE_STATUS_Pin, GPIO_PIN_SET);
		}
		break;
		case 0x03:
		{
			HAL_UART_Transmit(huart , (uint8_t *)at_ps_cmd, strlen((const char *)at_ps_cmd), 2000);
		}
		break;
		case 0x04:
		{
			HAL_UART_Transmit(huart , (uint8_t *)at_scence_cmd, strlen((const char *)at_scence_cmd), 2000);
		}
		break;
		case 0x05:
		{
			HAL_UART_Transmit(huart , (uint8_t *)at_action_cmd, strlen((const char *)at_action_cmd), 2000);
		}
		break;
		case 0x06:
		{
			HAL_UART_Transmit(huart , (uint8_t *)at_action_check_cmd, strlen((const char *)at_action_check_cmd), 2000);
		}
		break;
		case 0x07://connect
		{
			/* http
			lte_recv_flag++;
			*/
			if(lte_recv_flag_tmp==lte_recv_flag)
			{
				lte_recv_flag_tmp_times++;
				if(lte_recv_flag_tmp_times>120)
				{
					lte_recv_flag_tmp_times=0;
					
					HAL_UART_Transmit(huart , (uint8_t *)at_tcp_connect_cmd, strlen((const char *)at_tcp_connect_cmd), 2000);
				}
			}
			else
			{
				HAL_UART_Transmit(huart , (uint8_t *)at_tcp_connect_cmd, strlen((const char *)at_tcp_connect_cmd), 2000);
				lte_recv_flag_tmp=lte_recv_flag;
				lte_recv_flag_tmp_times=0;
			}
		}
		break;
		case 0x08:
		{
			/* http
			if(lte_recv_flag_tmp==lte_recv_flag)
			{
				lte_recv_flag_tmp_times++;
				if(lte_recv_flag_tmp_times>10)
				{
					lte_recv_flag_tmp_times=0;
					HAL_UART_Transmit(huart , (uint8_t *)at_http_url_cmd, strlen((const char *)at_http_url_cmd), 2000);
				}
			}
			else
			{
				HAL_UART_Transmit(huart , (uint8_t *)at_http_url_cmd, strlen((const char *)at_http_url_cmd), 2000);
				lte_recv_flag_tmp=lte_recv_flag;
				lte_recv_flag_tmp_times=0;
			}
			*/
			//data no data send
			
		}
		break;
		case 0x09:
		{
			/*http
			HAL_UART_Transmit(huart , (uint8_t *)at_http_url_data, strlen((const char *)at_http_url_data), 2000);
			*/
			//data  fushi data send
			status->central_control_payloadbuff[0]=0x55;
			status->central_control_payloadbuff[1]=0xaa;
			status->central_control_payloadbuff[2]=status->central_control_address;
			status->central_control_payloadbuff[3]=status->central_control_payloadbuff_len+3;
			status->central_control_payloadbuff[4]=0x01;
			crc_tmp=CRC16 ((const uint8_t *)status->central_control_payloadbuff, status->central_control_payloadbuff_len+5);
			status->central_control_payloadbuff[status->central_control_payloadbuff_len+5]=crc_tmp/256;
			status->central_control_payloadbuff[status->central_control_payloadbuff_len+6]=crc_tmp%256;
			HAL_UART_Transmit(huart , (uint8_t *)status->central_control_payloadbuff, status->central_control_payloadbuff_len+7, 2000);
			lte_recv_flag=8;
		}
		break;
		case 0x0a://send close
		{
			/*http
			//printf("at_http_post_cmd\r\n");
			if(lte_recv_flag_tmp==lte_recv_flag)
			{
				printf("at_http_post_cmd1\r\n");
				lte_recv_flag_tmp_times++;
				if(lte_recv_flag_tmp_times>10)
				{
					lte_recv_flag_tmp_times=0;
					HAL_UART_Transmit(huart , (uint8_t *)at_http_post_cmd, strlen((const char *)at_http_post_cmd), 2000);
				}
			}
			else
			{
				printf("at_http_post_cmd2\r\n");
				HAL_UART_Transmit(huart , (uint8_t *)at_http_post_cmd, strlen((const char *)at_http_post_cmd), 2000);
				lte_recv_flag_tmp=lte_recv_flag;
				lte_recv_flag_tmp_times=0;
			}
			*/
			if(lte_recv_flag_tmp==lte_recv_flag)
			{
				lte_recv_flag_tmp_times++;
				if(lte_recv_flag_tmp_times>60)
				{
					lte_recv_flag_tmp_times=0;
					HAL_UART_Transmit(huart , (uint8_t *)at_tcp_close_cmd, strlen((const char *)at_tcp_close_cmd), 2000);
				}
			}
			else
			{
				HAL_UART_Transmit(huart , (uint8_t *)at_tcp_close_cmd, strlen((const char *)at_tcp_close_cmd), 2000);
				lte_recv_flag_tmp=lte_recv_flag;
				lte_recv_flag_tmp_times=0;
			}
			
		}
		break;
		case 0x0b:
		{
			/*
		
			USER_CENTRAL_CONTROL_STATUS_T *status=user_central_control_get_status();
			status->central_control_payloadbuff[0]=0x55;
			status->central_control_payloadbuff[1]=0xaa;
			status->central_control_payloadbuff[2]=status->central_control_address;
			status->central_control_payloadbuff[3]=0x01;
			status->central_control_payloadbuff[4]=0x44+2;
			crc_tmp=CRC16 ((const uint8_t *)status->central_control_payloadbuff, 0x44+5);
			status->central_control_payloadbuff[ 0x44+5]=crc_tmp/256;
			status->central_control_payloadbuff[ 0x44+6]=crc_tmp%256;
			printf("status->central_control_payloadbuff_len+7\r\n");
			HAL_UART_Transmit(huart , (uint8_t *)status->central_control_payloadbuff,  0x44+7, 2000);
			HAL_UART_Transmit(huart , (uint8_t *)at_http_post_cmd, strlen((const char *)at_http_post_cmd), 2000);
			*/
			#if 0
			if(lte_recv_flag_tmp==lte_recv_flag)
			{
				printf("at_tcp_out_cmd %d\r\n",lte_recv_flag_tmp_times);
				lte_recv_flag_tmp_times++;
				if(lte_recv_flag_tmp_times>10)
				{
					lte_recv_flag_tmp_times=0;
					HAL_UART_Transmit(huart , (uint8_t *)at_tcp_out_cmd, strlen((const char *)at_tcp_out_cmd), 2000);
				}
			}
			else
			{
				//HAL_UART_Transmit(huart , (uint8_t *)at_tcp_out_cmd, strlen((const char *)at_tcp_out_cmd), 2000);
				lte_recv_flag_tmp=lte_recv_flag;
				lte_recv_flag_tmp_times=0;
			}
			#else
				HAL_GPIO_WritePin(CON_4V1_GPIO_Port, CON_4V1_Pin, GPIO_PIN_RESET);
				lte_recv_flag=0X0c;
			#endif
		}
		break;
		case 0x0c:
			HAL_GPIO_WritePin(CON_4V1_GPIO_Port, CON_4V1_Pin, GPIO_PIN_SET);
			lte_recv_flag=0;
		break;
		
		
	}
}

void user_lte_drive_add_data(uint8_t data)
{
	user_uart_serial_add_data(&user_lte_serial_handle,data);
}

uint8_t user_lte_drive_handle(void)
{
//	uint8_t i;
	uint16_t data_recv_len_tmp=0;
	uint16_t lte_recv_payload_len_tmp=0;
	uint16_t lte_crc_tmp=0;
	char *data_tmp1;
	char *data_tmp2;
	uint16_t len_tmp;
	USER_CENTRAL_CONTROL_STATUS_T*  tmp=user_central_control_get_status();
	if(user_uart_serial_get_datalength(&user_lte_serial_handle))
	{
		lte_action_sendtime=0;
		

		printf("user_lte_drive_handle is %d\r\n",lte_recv_flag);
		switch(lte_recv_flag)
		{
			case 0x00://at
			{
				
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				if(strstr((const char *)user_lte_recvbuff_tmp,"OK")!=NULL)
				{
					lte_recv_flag++;
				}
			}
			break;
			case 0x01://AT+CPIN?
			{
				
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				if(strstr((const char *)user_lte_recvbuff_tmp,"READY")!=NULL)
				{
					lte_recv_flag++;
				}
				else
				{
					lte_recv_flag=0;
				}
			}
			break;
			case 0x02://AT+CREG?
			{
				
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				data_tmp1=strstr((const char *)user_lte_recvbuff_tmp,"\r\n");
				if(data_tmp1!=NULL)
				{
					data_tmp1=data_tmp1+2;
					data_tmp2=strstr((const char *)data_tmp1,"\r\n");
					if(data_tmp2!=NULL)
					{
						
						memset(user_lte_recvbuff_tmp2,0,sizeof(user_lte_recvbuff_tmp2));
						memcpy(user_lte_recvbuff_tmp2,data_tmp1,&(data_tmp2[0])-&(data_tmp1[0]));
						//printf("user_lte_recvbuff_tmp2 is %s\r\n",user_lte_recvbuff_tmp2);
						if(strstr((const char *)user_lte_recvbuff_tmp2,"CREG")!=NULL)
						{
							
							if(user_lte_recvbuff_tmp2[9]=='1')
							{
								lte_recv_flag++;
							}
						}
					}
						
				}
			}
			break;
			case 0x03://AT+CGREG?
			{
				
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				data_tmp1=strstr((const char *)user_lte_recvbuff_tmp,"\r\n");
				if(data_tmp1!=NULL)
				{
					data_tmp1=data_tmp1+2;
					data_tmp2=strstr((const char *)data_tmp1,"\r\n");
					if(data_tmp2!=NULL)
					{
						memset(user_lte_recvbuff_tmp2,0,sizeof(user_lte_recvbuff_tmp2));
						memcpy(user_lte_recvbuff_tmp2,data_tmp1,&(data_tmp2[0])-&(data_tmp1[0]));
						//printf("user_lte_recvbuff_tmp2 is %s\r\n",user_lte_recvbuff_tmp2);
						if(strstr((const char *)user_lte_recvbuff_tmp2,"CGREG")!=NULL)
						{
							if(user_lte_recvbuff_tmp2[10]=='1')
							{
								lte_recv_flag++;
							}
						}
					}
						
				}
			}
			break;
			case 0x04://AT+QICSGP
			{
				
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				if(strstr((const char *)user_lte_recvbuff_tmp,"OK")!=NULL)
				{
					lte_recv_flag++;
				}
			}
			break;
			case 0x05://AT+QIACT
			{
				
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				if(strstr((const char *)user_lte_recvbuff_tmp,"OK")!=NULL)
				{
					lte_recv_flag++;
				}
			}
			break;
			case 0x06://AT+QIACT?
			{
				
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				//if(strstr((const char *)user_lte_recvbuff_tmp,"1,1")!=NULL)
				{
					//printf("0x06 ok\r\n");
					lte_recv_flag++;
				}
				//else
				{
					//chongqi
				}
			}
			break;
			case 0x07:
			{
				/*http
				//if(strstr((const char *)user_lte_recvbuff_tmp,"1,1")!=NULL)
				{
					//printf("0x06 ok\r\n");
					lte_recv_flag++;
				}
				//else
				{
					//chongqi
				}
				*/
				//connect
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_check_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				if(strstr((const char *)user_lte_recvbuff_tmp,"\r\n")!=NULL)
				{
					if(strstr((const char *)user_lte_recvbuff_tmp,"\r\nCONNECT")!=NULL)
					{
						data_tmp1=strstr((const char *)user_lte_recvbuff_tmp,"\r\nCONNECT");
						data_tmp1=data_tmp1+10;
						len_tmp=(data_tmp1)-&(user_lte_recvbuff_tmp[0])+1;
						
						printf("CONNECT len is %d %d\r\n",len_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
						user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,len_tmp);
						lte_recv_flag++;
						
					}
					else if(strstr((const char *)user_lte_recvbuff_tmp,"\r\nERROR")!=NULL)
					{
						//lte_recv_flag=0;
						printf("user_lte_recvbuff_tmp ERROR \r\n");
						user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
					}
				}
				else
				{
					user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				}
			}
			break;
			case 0x08:
				/*http
				if(strstr((const char *)user_lte_recvbuff_tmp,"CONNECT")!=NULL)
				{
					lte_recv_flag++;
				}
				*/
				//tcp tou
				
				if(user_uart_serial_get_datalength(&user_lte_serial_handle)>=5)
				{
					
					lte_recv_flag_tmp_times_times=0;
					memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
					
					data_recv_len_tmp=0;
					data_recv_len_tmp=user_uart_serial_check_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,1);
					if(user_lte_recvbuff_tmp[0]!=0x55)
					{
						
						memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
						data_recv_len_tmp=0;
						data_recv_len_tmp=user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
						if(strstr((const char *)user_lte_recvbuff_tmp,"NO")!=NULL)
						{
							printf("connect error\r\n");
							lte_recv_flag=0x0a;
							return 0;
						}
						
					}
					

					data_recv_len_tmp=0;
					memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
					data_recv_len_tmp=user_uart_serial_check_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,2);
					if(data_recv_len_tmp==2)
					{
						if(user_lte_recvbuff_tmp[1]==0xaa)
						{
							data_recv_len_tmp=0;
							memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
							data_recv_len_tmp=user_uart_serial_check_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,4);
							lte_recv_payload_len_tmp=user_lte_recvbuff_tmp[3]+4;
							if(user_uart_serial_get_datalength(&user_lte_serial_handle)>=lte_recv_payload_len_tmp)
							{
								memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
								user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,lte_recv_payload_len_tmp);
								lte_crc_tmp=CRC16 ((const uint8_t *)user_lte_recvbuff_tmp,lte_recv_payload_len_tmp-2);
								if((user_lte_recvbuff_tmp[lte_recv_payload_len_tmp-2]==lte_crc_tmp/256)
								&&(user_lte_recvbuff_tmp[lte_recv_payload_len_tmp-1]==lte_crc_tmp%256))
								{
									printf("lte crc is ok %d %d\r\n",tmp->central_control_address,user_lte_recvbuff_tmp[2]);
									switch(user_lte_recvbuff_tmp[4])
									{
										case Lte_READ_DATA://读数据
											lte_recv_flag=9;
										break;
										case Lte_SET_TIME_DATA://设置腐蚀仪器时间
											if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
												user_fushi_set_fushi_status( FUSHI_SET_DEVICE_TIME,0,&(user_lte_recvbuff_tmp[5]));
										break;
										case  Lte_SET_CHECK_DATA://设置采集时间
											if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
												user_fushi_set_fushi_status( FUSHI_SET_CHECK_TIME,user_lte_recvbuff_tmp[5]*256+user_lte_recvbuff_tmp[6],NULL);
										break;
										case Lte_SET_PRO://阴极保护开关
											if(user_lte_recvbuff_tmp[5])
											{
												if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
													user_fushi_set_fushi_status( FUSHI_SET_POR_OPEN,0,NULL);
											}
											else
											{
												if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
													user_fushi_set_fushi_status( FUSHI_SET_POR_CLOSE,0,NULL);
											}
											
										break;
										case Lte_SET_DEVICE1_PRO://探头1是否极化
											if(user_lte_recvbuff_tmp[5])
											{
												if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
													user_fushi_set_fushi_status( FUSHI_SET_DEVICE1_OPEN,0,NULL);
											}
											else
											{
												if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
													user_fushi_set_fushi_status( FUSHI_SET_DEVICE1_CLOSE,0,NULL);
											}
										break;
										case Lte_SET_DEVICE2_PRO://探头2是否极化
											if(user_lte_recvbuff_tmp[5])
											{
												if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
													user_fushi_set_fushi_status( FUSHI_SET_DEVICE2_OPEN,0,NULL);
											}
											else
											{
												if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
													user_fushi_set_fushi_status( FUSHI_SET_DEVICE2_CLOSE,0,NULL);
											}
										break;
										case Lte_SET_RESET://reset
											if(user_lte_recvbuff_tmp[2]==tmp->central_control_address)
												user_fushi_set_fushi_status( FUSHI_SET_DEVICE_RESET,0,NULL);
										break;
								
									
									
									
									}
								}
							}
						}
						else
						{
							user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,2);
						}
					}
				}
				else
				{
					
					lte_recv_flag_tmp_times_times++;
					printf("lte_recv_flag_tmp_times_times1 is %d\r\n",lte_recv_flag_tmp_times_times);
					if(lte_recv_flag_tmp_times_times>LTE_TIME_OUT)
					{
						lte_recv_flag_tmp_times_times=0;
						lte_recv_flag=0x0b;
					}
				}
			break;
			case 0x09:
				/*http
				if(strstr((const char *)user_lte_recvbuff_tmp,"OK")!=NULL)
				{
					lte_recv_flag++;
				}
				*/
			break;
			case 0x0a://socket close
				/*http
				printf("data is %s",user_lte_recvbuff_tmp);
				//if(strstr((const char *)user_lte_recvbuff_tmp,"CONNECT")!=NULL)
				{
					lte_recv_flag++;
				}
				*/
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_check_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				if(strstr((const char *)user_lte_recvbuff_tmp,"\r\n")!=NULL)
				{
					if(strstr((const char *)user_lte_recvbuff_tmp,"\r\nOK")!=NULL)
					{
						user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
						lte_recv_flag=7;
						
					}
					else
					{
						user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				
					}
					
						
				}
				else
				{
					user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				}
				
			break;
			case 0x0b://+++
				/*http
				//if(strstr((const char *)user_lte_recvbuff_tmp,"OK")!=NULL)
				{
					lte_recv_flag++;
				}
				*/
				memset(user_lte_recvbuff_tmp,0,sizeof(user_lte_recvbuff_tmp));
				data_recv_len_tmp=0;
				data_recv_len_tmp=user_uart_serial_check_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				if(strstr((const char *)user_lte_recvbuff_tmp,"\r\n")!=NULL)
				{
					if(strstr((const char *)user_lte_recvbuff_tmp,"\r\nOK")!=NULL)
					{
						user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
						lte_recv_flag=0x0a;
						
					}
					else
					{
						user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				
					}
					
						
				}
				else
				{
					user_uart_serial_get_data(&user_lte_serial_handle,user_lte_recvbuff_tmp,user_uart_serial_get_datalength(&user_lte_serial_handle));
				}
			break;
			
		}
		
	}
	else
	{
		if(lte_recv_flag==0x08)
		{
			printf("lte_recv_flag_tmp_times_times2 is %d\r\n",lte_recv_flag_tmp_times_times);
			lte_recv_flag_tmp_times_times++;
			if(lte_recv_flag_tmp_times_times>LTE_TIME_OUT)
			{
				lte_recv_flag_tmp_times_times=0;
				lte_recv_flag=0x0b;
			}
		}
	}
	return 0;
			
}


